<div class="layuimini-container">
    <form id="app-form" class="layui-form layuimini-form">
        <style>
            #loading {
                display: none;
                position: fixed;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                padding: 50px;
                background: white;
                border: 1px solid #ccc;
                z-index: 1000;
            }
        </style>
        <div id="loading">Loading...</div>
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input type="text" name="title" class="layui-input" lay-verify="required" placeholder="请输入名称" value="{$row.title|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">图片</label>
            <div class="layui-input-block layuimini-upload">
                <input name="image" class="layui-input layui-col-xs6"   placeholder="请上传图片" value="{$row.image|default=''}">
                <div class="layuimini-upload-btn">
                    <span><a class="layui-btn" data-upload="image" data-upload-number="one" data-upload-exts="png|jpg|ico|jpeg|glb" data-upload-icon="image"><i class="fa fa-upload"></i> 上传</a></span>
                    <span><a class="layui-btn layui-btn-normal" id="select_image" data-upload-select="image" data-upload-number="one" data-upload-mimetype="image/*"><i class="fa fa-list"></i> 选择</a></span>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">轮播图片</label>
            <div class="layui-input-block layuimini-upload">
                <input name="images" class="layui-input layui-col-xs6"   placeholder="请上传轮播图片" value="{$row.images|default=''}">
                <div class="layuimini-upload-btn">
                    <span><a class="layui-btn" data-upload="images" data-upload-number="more" data-upload-exts="png|jpg|ico|jpeg" data-upload-icon="image" data-upload-sign=""><i class="fa fa-upload"></i> 上传</a></span>
                    <span><a class="layui-btn layui-btn-normal" id="select_images" data-upload-select="images" data-upload-number="more" data-upload-mimetype="image/*" data-upload-sign=""><i class="fa fa-list"></i> 选择</a></span>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">3D模型文件</label>
            <div class="layui-input-block layuimini-upload">
                <input type="file" id="fileInput">
                <a style="cursor: pointer;color:blue;text-decoration: blue" onclick="uploadFile()">上传文件</a>
            </div>
            <input type="text" readonly name="file_model" id="file_model" style="opacity: 0.5" value="{$row.file_model|default=''}">

        </div>
        <script>
            function uploadFile() {
                $("#loading").show()
                var fileInput = document.getElementById('fileInput');
                var file = fileInput.files[0]; // 获取选中的文件
                var formData = new FormData(); // 创建FormData对象
                formData.append('file', file); // 将文件添加到FormData对象中

                var xhr = new XMLHttpRequest(); // 创建XMLHttpRequest对象
                xhr.open('POST', "{:url('admin/goods/upload')}", true); // 设置请求类型、URL和异步标志

                xhr.onload = function () {
                    if (xhr.status === 200) {
                        console.log('File uploaded successfully');
                        console.log(xhr.responseText); // 显示服务器响应
                        alert('上传成功')
                        $("#file_model").val(xhr.responseText)
                        $("#loading").hide()
                    } else {
                        console.error('Upload failed');
                    }
                };

                xhr.send(formData); // 发送数据
            }
        </script>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="sort" class="layui-input"  placeholder="请输入排序" value="{$row.sort|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="text" name="status" class="layui-input"  placeholder="请输入状态" value="{$row.status|default=''}">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注说明</label>
            <div class="layui-input-block">
                <textarea name="remark" class="layui-textarea"  placeholder="请输入备注说明">{$row.remark|raw|default=''}</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">详情</label>
            <div class="layui-input-block" style="height: 200px;">
                <textarea style="height: 200px;" name="content" id="content" class="layui-textarea editor"  placeholder="请输入详情">{$row.content|raw|default=''}</textarea>
            </div>
        </div>
        <div class="hr-line"></div>
        <div class="layui-form-item text-center">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit>确认</button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">重置</button>
        </div>

    </form>
</div>